package com.c.ctgproject.adapter.service

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseRecyclerViewAdapter
import com.c.ctgproject.entity.service.ServiceLogisticsEntity
import com.c.ctgproject.ui.service.ServiceLogisticsDetailActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.handlerNull
import org.jetbrains.anko.startActivity

class ServiceLogisticsAdapter(private val context: Context, private val mList: List<ServiceLogisticsEntity.DataBean.ListBean>) : BaseRecyclerViewAdapter(context, mList) {

    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_service_logistics_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mCreateTimeTV.text = data.lgsCreateTime.handlerNull()
            "车主姓名:${data.carOwner.handlerNull()}".also { holder.mOwnerNameTV.text = it }
            "车主电话:${data.carPhone.handlerNull()}".also { holder.mPhoneTV.text = it }
            "车牌号:${data.carPlate.handlerNull()}".also { holder.mCarNumberTV.text = it }
            "预计拖车时间:${data.planTrailerTime.handlerNull()}".also { holder.yujituocheshijian.text = it }
            "派车时间:${data.distributeTime.handlerNull()}".also { holder.paicheshijian.text = it }
            "托运时间:${data.realCltTime.handlerNull()}".also { holder.tuoyunshijian.text = it }
            "送达时间:${data.finishTime.handlerNull()}".also { holder.songdashijian.text = it }
            val isDelay = when (data.isDelay) {
                "1" -> "延迟派单:是"
                "2" -> "延迟派单:否"
                else -> "延迟派单:-"
            }
            holder.yanchipaidan.text = isDelay
            holder.mParentLL.setOnClickListener {
                context.startActivity<ServiceLogisticsDetailActivity>(MyConstants.LGS_ID to data.lgsId.handlerNull(),
                    MyConstants.DATA to data
                )

            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mCreateTimeTV: TextView = view.findViewById(R.id.mCreateTimeTV)
        val mOwnerNameTV: TextView = view.findViewById(R.id.mOwnerNameTV)
        val mPhoneTV: TextView = view.findViewById(R.id.mPhoneTV)
        val mCarNumberTV: TextView = view.findViewById(R.id.mCarNumberTV)
        val yanchipaidan: TextView = view.findViewById(R.id.yanchipaidan)
        val yujituocheshijian: TextView = view.findViewById(R.id.yujituocheshijian)
        val paicheshijian: TextView = view.findViewById(R.id.paicheshijian)
        val tuoyunshijian: TextView = view.findViewById(R.id.tuoyunshijian)
        val songdashijian: TextView = view.findViewById(R.id.songdashijian)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
    }
}